
$(function(){
	new Vue({
		el:"#shopGoodSpecApp",
		data:{
			fullscreenLoading:false,
			activeName: 'first',
			goodLoacalStock:[],
			ids:[],
			searchGood:'',
			date:"",
			time:"",
			currentPage:1,
			totalSize:1,
			
		},
		created:function(){
			parent.vueData.$data.hreHtml="../goodSpecStock/index.html";
			parent.vueData.activeIndex  = "7";
			parent.vueData.getLeftNav("7")
			parent.vueData.$data.categoryIndex = 2
		    this.getAllGoodSpec("",1)	
		},
		methods:{
			
			getAllGoodSpec(keyWord,page){
			    this.fullscreenLoading = true;
			    let param = {
			    	shopId: getShopId(),
					keyword:keyWord,
					pageNum:page,
					admin_grade:"1",
			    }
			    axios({
			    	url: POSTURL.parameterSelectByShopId,
			    	method:'post',
			    	data: param
			    }).then(response => {
			    	this.fullscreenLoading = false;
			    	if (response.data.code === 100) {
						if(page === 1){
							if(response.data.result.pageCount<=1){
								this.totalSize =response.data.result.parameters.length
							}else{
							   this.totalSize = response.data.result.pageCount*10	
							}
							this.goodLoacalStock.length = 0;
							this.goodLoacalStock=[];
						}
						console.log(response.data.result);
			    		 this.goodLoacalStock = response.data.result.parameters
						 this.goodLoacalStock.forEach(obj=>{
							 obj.categoryName  =  obj.category.name
						 })
			    	} else {
			    		this.$message.error(response.data.message);
			    	}
			    }).catch(error => {
			    	this.fullscreenLoading = false;
			    	console.log(error);
			    	this.$message.error('服务器出错!');
			    })	
			},
			handleCurrentChange(val) {
				 this.getAllGoodSpec(this.searchGood,val)	
			},
			handleClick(tab, event) {
				console.log(tab.name);
			},
			 
			handlePlatformCommand(command){
				console.log(command);
			},
			clickSearchGood(){
				 this.getAllGoodSpec(this.searchGood,1)	
			},
			handleSelectionChange(val) {
				this.ids = [];
				val.forEach(obj=>{
					this.ids.push(obj.uid)
				})
			},
			addGoodProp(){
				parent.vueData.handleOpen(75,2)
			},
			eidtGoodProp(val){
				console.log(val);
				localStorage.setItem("goodCategoryId",val.uid);
				parent.vueData.handleOpen(78,2)
			},
			
			// 删除商品规格
			deleteGoodProp(val){
				this.deleteProp([val.uid])
			},
			mutDeleteGood(){
				this.deleteProp(this.ids)
			},
			deleteProp(val){
				this.fullscreenLoading = true;
				let param = {
					parameterId: val,
					admin_grade:"1",
					
				}
				axios({
					url: POSTURL.deleteParameter,
					method: 'post',
					data: param
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
						this.$message({
							showClose: true,
							message: response.data.message,
							type: 'success'
						});
						 this.getAllGoodSpec(this.searchGood,1)	
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				})
			}
			
		}
	})
})